package com.gateon.hw.system.service.impl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.gateon.hw.system.entity.SupplierContract;
import com.gateon.hw.system.service.ISupplierContractService;
import com.gateon.hw.system.mapper.SupplierContractMapper;
import java.util.List;
import com.gateon.hw.client.system.resp.SupplierContractResp;
import com.gateon.hw.client.system.req.SupplierContractListReq;
import com.gateon.hw.client.system.req.SupplierContractAddReq;
import com.gateon.hw.client.system.req.SupplierContractUpdateReq;

import com.gateon.hw.base.vo.Result;
import org.springframework.beans.BeanUtils;



/**
* 合同信息表 SupplierContractServiceImpl
* Created by leslie on 2020-4-29 15:38:04
*/
@Service
public class SupplierContractServiceImpl implements ISupplierContractService{
    @Autowired
    private SupplierContractMapper supplierContractMapper;

    @Override
    public ResultModel<IPage<SupplierContractResp>> list(SupplierContractListReq req) {
        Page page = new Page(req.getCurrentPage(), req.getPageSize());
        QueryWrapper<SupplierContract> query = Wrappers.query();
        query.orderByDesc("id");
        IPage iPage = supplierContractMapper.selectPage(page, query);
        if (CollectionUtils.isEmpty(iPage.getRecords())) {
            return ResultUtil.success();
        }
        List<SupplierContractResp> responseList = ConvertDtoUtils.convertList(iPage.getRecords(), SupplierContractResp.class);
        iPage.setRecords(responseList);
        return ResultUtil.success(iPage);
    }

    @Override
    public ResultModel<SupplierContractResp> detail(Long id) {
        SupplierContractResp resp=new SupplierContractResp();
        SupplierContract re=supplierContractMapper.selectById(id);
        BeanUtils.copyProperties(re,resp);
        return ResultUtil.success(resp);
    }
    @Transactional
    @Override
    public ResultModel insert(SupplierContractAddReq req) {
        SupplierContract re=new  SupplierContract();
        BeanUtils.copyProperties(req,re);
        supplierContractMapper.insert(re);
        return ResultUtil.success();
    }
    @Transactional
    @Override
    public ResultModel update(SupplierContractUpdateReq req) {
        SupplierContract re=new  SupplierContract();
        BeanUtils.copyProperties(req,re);
        supplierContractMapper.updateById(re);
        return ResultUtil.success();
    }
    @Transactional
    @Override
    public ResultModel delete(Long  id) {
        supplierContractMapper.deleteById(id);
        return ResultUtil.success();
    }
}